/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.game.wordpuzzle;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author AritomoAbe
 */
public class ProcessGameResult implements GameAction {

    @Override
    public void processActionRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String gameId = request.getParameter("gameId");
        String userName = request.getParameter("userName");
        String answer = request.getParameter("answer");
        Game game = GameManager.getGameManager().getActiveGame(gameId);
        if (game != null && userName != null) {
            if (game.getOwnerName().equals(userName)) {
                boolean bTrue = false;
                if (game.getAnswer().equals(answer)) {
                    bTrue = true;
                }

                PrintWriter out = response.getWriter();
                try {
                    out.println(bTrue);
                } finally {
                    out.close();
                }
            }
        }
    }
}
